package com.marchsoft.dao;

import com.marchsoft.common.mapper.CommentMapper;
import com.marchsoft.domain.Group;
import com.marchsoft.vo.GroupExtra;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.FetchType;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public interface GroupMapper extends CommentMapper<Group> {
    /**
     * 查询所有的兴趣小组的信息
     * @return 所有小组信息
     */
    @Select("SELECT * FROM `group`")
    @Results({
            @Result(id=true,column="id",property="id"),
            @Result(column="major_field",property="majorField"),
            @Result(column="id",property="teacherList",
                    many=@Many(
                            select="com.marchsoft.dao.TeacherMapper.queryTeacherInfo",
                            fetchType= FetchType.LAZY)
            )
    })
    List<GroupExtra> queryGroupAll();

    /**
     * 根据小组id查询其信息（包含老师信息）
     * @param gid 小组id
     * @return 一条小组信息
     */
    @Select("SELECT * FROM `group` WHERE id=#{gid}")
    @Results({
            @Result(id=true,column="id",property="id"),
            @Result(column="major_field",property="majorField"),
            @Result(column="id",property="teacherList",
                    many=@Many(
                            select="com.marchsoft.dao.TeacherMapper.queryTeacherInfo",
                            fetchType= FetchType.LAZY)
            )
    })
    GroupExtra queryGroupByGid(Integer gid);
}
